package com.lst.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lst.api.constant.DeleteEnum;
import com.lst.api.entity.TaxLevel;
import com.lst.api.mapper.TaxLevelMapper;
import com.lst.api.service.ITaxLevelService;
import com.lst.api.vo.CodeAndNameVo;
import com.lst.tools.mybatis.service.impl.BaseService;
import com.lst.tools.mybatis.utils.ExpandSqlUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 税务等级管理表业务层实现
 *
 * @author Frank
 * @date 2019-12-30 10:31:38
 * @version: V1.0
 */
@Service
public class TaxLevelService extends BaseService<TaxLevelMapper, TaxLevel> implements ITaxLevelService {

    @Override
    public List<CodeAndNameVo> listTaxLevel() {
        QueryWrapper<TaxLevel> queryWrapper = new QueryWrapper();
        queryWrapper.eq(TaxLevel.IS_DELETE, DeleteEnum.DELETE_NO.getKey());
        queryWrapper
                .orderByAsc(ExpandSqlUtils.getIsNullOrderBy(TaxLevel.SORT, false))
                .orderByAsc(TaxLevel.SORT)
                .orderByDesc(TaxLevel.CREATE_AT)
                .orderByDesc(TaxLevel.ID);
        List<TaxLevel> taxLevelList = super.list(queryWrapper);
        if (CollectionUtils.isEmpty(taxLevelList)) {
            return Collections.EMPTY_LIST;
        }
        return taxLevelList
                .stream()
                .map(item -> new CodeAndNameVo(item.getLevel(), item.getLevel()))
                .collect(Collectors.toList());
    }
}